package cn.jly.boot.mp.redis;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

/**
 * @author lanyangji
 * @description jedis连接redis测试
 * @date 2020/12/29 下午 7:42
 */
public class JedisTest {
    public static void main(String[] args) {
        String host = "192.168.172.101";
        int port = 7001;
//        final String ping;
//        try (Jedis jedis = new Jedis(host, port)) {
//            jedis.auth("123456");
//            ping = jedis.ping();
//        }
//        System.out.println("ping = " + ping);

        final Jedis jedis = JedisUtils.getJedisPool().getResource();
        jedis.auth("123456");
        final String ping = jedis.ping();
        System.out.println("ping = " + ping);

        // jedisCluster测试
        final GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(20);
        final String k1Val;
        try (JedisCluster jedisCluster = new JedisCluster(
                new HostAndPort(host, port),
                1000,
                100,
                10,
                "123456",
                config
        )) {
            k1Val = jedisCluster.get("k1");
        }
        System.out.println("k1Val = " + k1Val);
    }
}
